/*
* Client
*
* r5
*
* GNU General Public License v3.0
*/

package com.acme.bankapp.domain.client;

import java.util.*;

import com.acme.bankapp.domain.account.*;

public class Client {
	
	private ArrayList<Account> accounts = new ArrayList<>();
	
	private String name;
	private Gender gender;
	
	public Client(final String name, final Gender gender) {
		this.name = name;
		this.gender = gender;
	}
	
	public void addAccount(final Account a) {
		this.accounts.add(a);
	}
	
	public ArrayList<Account> getAccounts() {
		return this.accounts;
	}
	
	public String getName() {
		return this.name;
	}
	
	public Gender getGender() {
		return this.gender;
	}
	
	public String getClientSalutation() {
		return this.gender + " " + this.name;
	}
	
	@Override
	public int hashCode() {
		return this.getClass().hashCode() + this.gender.hashCode() + this.name.hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		Client other = (Client)obj;
		
		if(obj == null) {
			return false;
		}
		if(obj == this) {
			return true;
		}
		
		if(!this.name.equals(other.name)) {
			return false;
		}
		if(this.gender != other.gender) {
			return false;
		}
		
		return true;
	}
	
	@Override
	public String toString() {
		StringBuffer buf = new StringBuffer();
		
		buf.append(getClientSalutation()).append("'s accounts: \n");
		for(Account ac : accounts) {
			buf.append("\t").append(ac).append("\n");
		}
		
		return buf.toString();
	}
	
}
